package com.yanqu.road.server.cmd.activity.luckydraw;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LuckyDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_LUCKY_DRAW_DRAW_FROM_CHANNEL, desc = "")
public class LuckyDrawDrawFromChannelCmd extends AbstractCommand {

    private LuckyDrawProto.LuckyDrawRespMsg respMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        respMsg = LuckyDrawProto.LuckyDrawRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (respMsg.getRet() == 0) {
            Property property = PropertyHelper.parseStringToProperty(respMsg.getReward());
            player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.LuckyDraw, eLogMoneyType.LuckyDrawDrawReward);
        }
        player.sendPacket(ClientProtocol.U_LUCKY_DRAW_DRAW, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }

}
